//
//  OpinionViewController.m
//  安好
//
//  Created by 冯凯 on 14-11-25.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "OpinionViewController.h"
#import "SystemSettingTableViewCell.h"
#import "OpinionDetailViewController.h"
#import "AbnormalViewController.h"

@interface OpinionViewController ()

@end

@implementation OpinionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //加载导航条
    [self makeNavBar];
    //加载数据
    [self loadData];
    //加载tableView
    [self createTableView];
    
}
-(void)loadData
{
    self.setArray = @[@"提交意见"];
    self.ideaArray = @[@"异常退出",@"登录缓慢",@"部分功能无法使用",@"运行不够流畅",@"感觉很耗电",@"感觉很耗流量"];

    
}
#pragma mark - 配置导航条
-(void)makeNavBar
{
    self.navigationItem.title = @"意见反馈";
    // 返回按钮图片
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backMoreVC)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnImg;
}
#pragma mark - 创建tableView设置代理
-(void)createTableView
{
    self.systemTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0 , kScreenWidth, kScreenHeight - iOS7TopMargin) style:UITableViewStyleGrouped];
    self.systemTableView.delegate = self;
    self.systemTableView.dataSource = self;
    //隐藏横向和竖向的滑条
    self.systemTableView.showsHorizontalScrollIndicator = NO;
    self.systemTableView.showsVerticalScrollIndicator = NO;
    self.systemTableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    [self.view addSubview:self.systemTableView];
}
#pragma mark - 返回
- (void)backMoreVC
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - tableViewDelegate
/**
 *  设置 为 2 段
 */
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return self.setArray.count;
    }else{
        return self.ideaArray.count;
    }
}
//设置段头高
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return 46;
    }else{
    return 10;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (kScreenWidth == 414){
        return 56;
    }else{
        return 44;
    }
}
#pragma mark ----2中cell的加载
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SystemSettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SystemSettingTableViewCell"];
    if (cell == nil) {
        if (kScreenWidth == 414){
            cell = [[[NSBundle mainBundle] loadNibNamed:@"SystemSettingTableViewCell" owner:self options:nil] lastObject];

        }else{
            
            cell = [[[NSBundle mainBundle] loadNibNamed:@"SystemSettingTableViewCell" owner:self options:nil] firstObject];
        }
    }
    if (indexPath.section == 0) {
        
        cell.settingLabel.text = self.setArray[indexPath.row];
    }else if (indexPath.section == 1){
        cell.settingLabel.text = self.ideaArray[indexPath.row];

    }
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section== 1) {
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 46)];
        view.backgroundColor = [UIColor clearColor];
        UILabel * sectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 13, kScreenWidth, 20)];
        sectionLabel.font = [UIFont systemFontOfSize:LABEL_FONT_SIZE_CONTENT];
        if (kScreenWidth == 414){
            sectionLabel.frame = CGRectMake(15, 11, kScreenWidth, 20);
        }else{
            
        }
        sectionLabel.text = @"快速反馈";
        [view addSubview:sectionLabel];
        return view;
    }else{
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
        return view;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
        OpinionDetailViewController * opinionDetailViewController = [[OpinionDetailViewController alloc]init];
        opinionDetailViewController.opinionString = self.setArray[indexPath.row];
        [self.navigationController pushViewController:opinionDetailViewController animated:YES];
    }else{
        if (indexPath.row == 0) {
            AbnormalViewController * abnormalViewController = [[AbnormalViewController alloc]init];
            [self.navigationController pushViewController:abnormalViewController animated:YES];
        }else{
            OpinionDetailViewController * opinionDetailViewController = [[OpinionDetailViewController alloc]init];
            opinionDetailViewController.opinionString = self.ideaArray[indexPath.row];
            [self.navigationController pushViewController:opinionDetailViewController animated:YES];
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
